#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef pair<int, int> PII;

const int N = 5010;

int dp[N];
int n;

int main()
{
    cin >> n;
    vector<PII> c;
    for (int i = 1; i <= n; i ++ )
    {
        int a, b;
        cin >> a >> b;
        c.push_back(PII(a, b));
    }
    sort(c.begin(), c.end());
    for (int i = 1; i <= n; i ++ )
    {
        dp[i] = 1;
        for (int j = 1; j < i; j ++ )
            if (c[i - 1].second > c[j - 1].second)
                dp[i] = max(dp[i], dp[j] + 1);
    }
    int res = 0;
    for (int i = 1; i <= n; i ++ )
        res = max(res, dp[i]);
    cout << res << endl;

    return 0;
}